/**
 * 招聘管理管理初始化
 */
var Job = {
    id: "JobTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Job.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '主键id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '岗位名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '招聘人数', field: 'count', visible: true, align: 'center', valign: 'middle'},
            {title: '工作经验', field: 'work_year', visible: true, align: 'center', valign: 'middle'},
            {title: '学历', field: 'education', visible: true, align: 'center', valign: 'middle'},
            {title: '工作地点', field: 'workplace', visible: true, align: 'center', valign: 'middle'},
            {title: '工资范围', field: 'salary', visible: true, align: 'center', valign: 'middle'},
            {title: '岗位职责', field: 'duty', visible: true, align: 'center', valign: 'middle'},
            {title: '岗位要求', field: 'requirement', visible: true, align: 'center', valign: 'middle'},
            {title: '福利待遇', field: 'welfare', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'create_time', visible: true, align: 'center', valign: 'middle'},
            {title: '更新时间', field: 'update_time', visible: true, align: 'center', valign: 'middle'},
            {title: '是否删除', field: 'isDelName', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Job.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Job.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加招聘管理
 */
Job.openAddJob = function () {
    var index = layer.open({
        type: 2,
        title: '添加招聘管理',
        area: ['800px', '850px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/jobMgr/job_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看招聘管理详情
 */
Job.openJobDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '招聘管理详情',
            area: ['800px', '850px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/jobMgr/job_update/' + Job.seItem.id
        });
        this.layerIndex = index;
    }
};

Job.formParams = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    return queryData;
};

/**
 * 删除招聘管理
 */
Job.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/jobMgr/delete", function (data) {
            Feng.success("删除成功!");
            Job.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("jobId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询招聘管理列表
 */
Job.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Job.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Job.initColumn();
    var table = new BSTable(Job.id, "/jobMgr/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Job.formParams());
    Job.table = table.init();
});
